<script setup lang="ts">
import { ref, watch } from 'vue';

let text=ref("")

let isred=ref(false)

const sum=["你","尼","妮"]

watch(
    ()=>text.value,
    (newvalue,oldvalue)=>{
        console.log("oldvalue",oldvalue);
        console.log("newvalue",newvalue);

        sum.forEach(s=>{
            if(newvalue.includes(s)){
                let hf_text=newvalue.substring(0,newvalue.length-1);
                text.value=hf_text;
                alert("你输入的内容含有违禁词")
                isred.value=true;
            }
        })
    }

)

</script>
<template>
<input type="text" placeholder="请不要输入违禁词" v-model="text" class="yecolor" :class="{recolor:isred}" />
</template>
<style scoped>
.yecolor{
    background-color:yellowgreen;
}
.recolor{
    background-color: red;
}
</style>